<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://wzc570738205.github.io').hostname,
    root: '/',
    scheme: 'Gemini',
    version: '7.7.0',
    exturl: true,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":true,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="变量的数据类型为什么需要数据类型在计算机中，不同的数据所需占用的存储空间不同，为了充分利用存储空间，于是定义了不同的数据类型。而且，不同的数据类型，寓意也不同。">
<meta property="og:type" content="article">
<meta property="og:title" content="javascript变量的数据类型">
<meta property="og:url" content="https://wzc570738205.github.io/2017/05/14/03-JS%E5%8F%98%E9%87%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/index.html">
<meta property="og:site_name" content="王志超的博客">
<meta property="og:description" content="变量的数据类型为什么需要数据类型在计算机中，不同的数据所需占用的存储空间不同，为了充分利用存储空间，于是定义了不同的数据类型。而且，不同的数据类型，寓意也不同。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2017-05-14T15:59:27.000Z">
<meta property="article:modified_time" content="2020-01-20T07:16:25.880Z">
<meta property="article:author" content="王志超">
<meta property="article:tag" content="javascript教程">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://wzc570738205.github.io/2017/05/14/03-JS%E5%8F%98%E9%87%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>javascript变量的数据类型 | 王志超的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">王志超的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">今天你更博学了吗</h1>
      
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-首页">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-关于">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-标签">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-分类">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-归档">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL3d6YzU3MDczODIwNQ==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wzc570738205.github.io/2017/05/14/03-JS%E5%8F%98%E9%87%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/logo.png">
      <meta itemprop="name" content="王志超">
      <meta itemprop="description" content="记录前端的点点滴滴">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="王志超的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          javascript变量的数据类型
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-05-14 15:59:27" itemprop="dateCreated datePublished" datetime="2017-05-14T15:59:27+00:00">2017-05-14</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-01-20 07:16:25" itemprop="dateModified" datetime="2020-01-20T07:16:25+00:00">2020-01-20</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%89%8D%E7%AB%AF%E7%9F%A5%E8%AF%86/" itemprop="url" rel="index">
                    <span itemprop="name">前端知识</span>
                  </a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2017/05/14/03-JS%E5%8F%98%E9%87%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/#comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2017/05/14/03-JS%E5%8F%98%E9%87%8F%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="变量的数据类型"><a href="#变量的数据类型" class="headerlink" title="变量的数据类型"></a>变量的数据类型</h2><h3 id="为什么需要数据类型"><a href="#为什么需要数据类型" class="headerlink" title="为什么需要数据类型"></a>为什么需要数据类型</h3><p>在计算机中，不同的数据所需占用的存储空间不同，为了充分利用存储空间，于是定义了不同的数据类型。而且，不同的数据类型，寓意也不同。</p>
<a id="more"></a>
<div class="note success no-icon">
            <p>欢迎加入前端交流群：<a href="//shang.qq.com/wpa/qunwpa?idkey=f528775f242a7c39fe8512383febb8990e621bf97354c2fb82f6832097b7c501" target="_blank" rel="noopener">749539640</a> </p>
          </div>
<p>我们都知道，无论这个变量是字符串类型，还是数字类型，我们都可以直接用 <code>var</code> 去定义它。比如：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="string">'hello word'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> b = <span class="number">123</span>;</span><br></pre></td></tr></table></figure>

<p>为什么可以这样做呢？这是因为：JavaScript 是一种「弱类型语言」，或者说是一种「动态语言」，这意味着不需要提前声明变量的类型，在程序运行过程中，类型会自动被确定。</p>
<p><strong>JS 的变量数据类型，是在程序运行的过程中，根据等号右边的值来确定的</strong>。而且，变量的数据类型是可以变化的。比如说：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name = <span class="string">'qianguyihao'</span>;</span><br><span class="line"></span><br><span class="line">name = <span class="number">123</span>; <span class="comment">// 强制将变量 name 修改为 数字类型</span></span><br></pre></td></tr></table></figure>

<h3 id="JS中一共有六种数据类型"><a href="#JS中一共有六种数据类型" class="headerlink" title="JS中一共有六种数据类型"></a>JS中一共有六种数据类型</h3><ul>
<li><p><strong>基本数据类型（值类型）</strong>：String 字符串、Number 数值、Boolean 布尔值、Null 空值、Undefined 未定义。</p>
</li>
<li><p><strong>引用数据类型（引用类型）</strong>：Object 对象。</p>
</li>
</ul>
<p>注意：内置对象 Function、Array、Date、RegExp、Error等都是属于 Object 类型。也就是说，除了那五种基本数据类型之外，其他的，都称之为 Object类型。</p>
<blockquote>
<p>面试问：引用数据类型有几种？</p>
</blockquote>
<blockquote>
<p>面试答：只有一种，即 Object 类型。</p>
</blockquote>
<p><strong>数据类型之间最大的区别</strong>：</p>
<ul>
<li><p>基本数据类型：参数赋值的时候，传数值。</p>
</li>
<li><p>引用数据类型：参数赋值的时候，传地址（修改的同一片内存空间）。</p>
</li>
</ul>
<p>今天这篇文章，我们详细讲一下基本数据类型。</p>
<h2 id="String-字符串"><a href="#String-字符串" class="headerlink" title="String 字符串"></a>String 字符串</h2><h3 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h3><p>字符串型可以是引号中的任意文本，其语法为：双引号 <code>&quot;&quot;</code> 或者单引号 <code>&#39;&#39;</code>。</p>
<p>来看个示例。下面的这些，都是字符串：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="string">"abcde"</span>;</span><br><span class="line"><span class="keyword">var</span> b = <span class="string">"千古壹号"</span>;</span><br><span class="line"><span class="keyword">var</span> c = <span class="string">"123123"</span>;</span><br><span class="line"><span class="keyword">var</span> d = <span class="string">'哈哈哈哈哈'</span>;</span><br><span class="line"><span class="keyword">var</span> e = <span class="string">""</span>;     <span class="comment">//空字符串</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> f = haha; <span class="comment">// 没使用引号，到这里会直接报错。因为会被认为是js代码，但是之前并没有定义 haha。</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> a);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> b);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> c);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> d);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> e);</span><br></pre></td></tr></table></figure>

<p>控制台输出如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">string</span><br><span class="line">string</span><br><span class="line">string</span><br><span class="line">string</span><br><span class="line">string</span><br></pre></td></tr></table></figure>

<h3 id="引号的注意事项"><a href="#引号的注意事项" class="headerlink" title="引号的注意事项"></a>引号的注意事项</h3><p>1、单引号和双引号不能混用。比如下面这样写是不可以的：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">'hello";  // 报错：Uncaught SyntaxError: Invalid or unexpected token</span></span><br></pre></td></tr></table></figure>

<p>2、同类引号不能嵌套：双引号里不能再放双引号，单引号里不能再放单引号。</p>
<p>3、单引号里可以嵌套双引号；双引号里可以嵌套单引号。</p>
<h3 id="转义字符"><a href="#转义字符" class="headerlink" title="转义字符"></a>转义字符</h3><p>在字符串中我们可以使用<code>\</code>作为转义字符，当表示一些特殊符号时可以使用<code>\</code>进行转义。</p>
<ul>
<li><p><code>\&quot;</code> 表示 <code>&quot;</code></p>
</li>
<li><p><code>\&#39;</code> 表示 <code>&#39;</code></p>
</li>
<li><p><code>\\</code> 表示<code>\</code></p>
</li>
<li><p><code>\r</code> 表示回车</p>
</li>
<li><p><code>\n</code> 表示换行。n 的意思是 newline。</p>
</li>
<li><p><code>\t</code> 表示缩进。t 的意思是 tab。</p>
</li>
<li><p><code>\b</code> 表示空格。b 的意思是 blank。</p>
</li>
</ul>
<p>举例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str1 = <span class="string">"我说:\"今天\t天气真不错！\""</span>;</span><br><span class="line"><span class="keyword">var</span> str2 = <span class="string">"\\\\\\"</span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(str1);</span><br><span class="line"><span class="built_in">console</span>.log(str2);</span><br></pre></td></tr></table></figure>


<p>上方代码的打印结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">我说:&quot;今天	天气真不错！&quot;</span><br><span class="line">\\\</span><br></pre></td></tr></table></figure>

<h3 id="获取字符串的长度"><a href="#获取字符串的长度" class="headerlink" title="获取字符串的长度"></a>获取字符串的长度</h3><p>字符串是由若干个字符组成的，这些字符的数量就是字符串的长度。我们可以通过字符串的 length 属性可以获取整个字符串的长度。</p>
<p>代码举例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str1 = <span class="string">'千古壹号'</span>;</span><br><span class="line"><span class="keyword">var</span> str2 = <span class="string">'千古壹号，永不止步！'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> str3 = <span class="string">'qianguyihao'</span>;</span><br><span class="line"><span class="keyword">var</span> str4 = <span class="string">'qianguyihao, keep moving!'</span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(str1.length); <span class="comment">// 4</span></span><br><span class="line"><span class="built_in">console</span>.log(str2.length); <span class="comment">// 10</span></span><br><span class="line"><span class="built_in">console</span>.log(str3.length); <span class="comment">// 11</span></span><br><span class="line"><span class="built_in">console</span>.log(str4.length); <span class="comment">// 25</span></span><br></pre></td></tr></table></figure>

<p>由此可见，字符串的 length 属性，在判断字符串的长度时，会认为：</p>
<ul>
<li><p>一个中文算一个字符，一个英文算一个字符</p>
</li>
<li><p>一个标点符号（包括中文标点、英文标点）算一个字符</p>
</li>
<li><p>一个空格算一个字符</p>
</li>
</ul>
<h3 id="字符串拼接"><a href="#字符串拼接" class="headerlink" title="字符串拼接"></a>字符串拼接</h3><p>多个字符串之间可以使用加号 <code>+</code> 进行拼接。</p>
<p><strong>拼接语法</strong>：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">字符串 + 任意数据类型 &#x3D; 拼接之后的新字符串;</span><br></pre></td></tr></table></figure>

<p><strong>拼接规则</strong>：拼接前，会把与字符串相加的这个数据类型转成字符串，然后再拼接成一个新的字符串。</p>
<p><strong>代码举例</strong>：（字符串与六大数据类型相加）</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str1 = <span class="string">'千古壹号'</span> + <span class="string">'永不止步'</span>;</span><br><span class="line"><span class="keyword">var</span> str2 = <span class="string">'千古壹号'</span> + <span class="number">666</span>;</span><br><span class="line"><span class="keyword">var</span> str3 = <span class="string">'千古壹号'</span> + <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">var</span> str4 = <span class="string">'千古壹号'</span> + <span class="literal">null</span>;</span><br><span class="line"><span class="keyword">var</span> str5 = <span class="string">'千古壹号'</span> + <span class="literal">undefined</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> obj = &#123; <span class="attr">name</span>: <span class="string">'千古壹号'</span>, <span class="attr">age</span>: <span class="number">28</span> &#125;;</span><br><span class="line"><span class="keyword">var</span> str6 = <span class="string">'千古壹号'</span> + obj;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(str1);</span><br><span class="line"><span class="built_in">console</span>.log(str2);</span><br><span class="line"><span class="built_in">console</span>.log(str3);</span><br><span class="line"><span class="built_in">console</span>.log(str4);</span><br><span class="line"><span class="built_in">console</span>.log(str5);</span><br><span class="line"><span class="built_in">console</span>.log(str6);</span><br></pre></td></tr></table></figure>

<p>打印结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">千古壹号永不止步</span><br><span class="line"></span><br><span class="line">千古壹号666</span><br><span class="line"></span><br><span class="line">千古壹号true</span><br><span class="line"></span><br><span class="line">千古壹号null</span><br><span class="line"></span><br><span class="line">千古壹号undefined</span><br><span class="line"></span><br><span class="line">千古壹号[object Object]</span><br></pre></td></tr></table></figure>


<h2 id="数值型：Number"><a href="#数值型：Number" class="headerlink" title="数值型：Number"></a>数值型：Number</h2><p>在JS中所有的数值都是 Number 类型，包括整数和浮点数（小数）。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">100</span>; <span class="comment">// 定义一个变量 a，并且赋值整数100</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> a); <span class="comment">// 输出变量 a 的类型</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> b = <span class="number">12.3</span>; <span class="comment">// 定义一个变量 b，并且赋值浮点数 12.3</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> a);</span><br></pre></td></tr></table></figure>

<p>上方代码的输出结果为：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">number</span><br><span class="line"></span><br><span class="line">number</span><br></pre></td></tr></table></figure>

<p>再次补充：在 JS 中，只要是数，就是 Number 数值型的。无论整浮、浮点数（即小数）、无论大小、无论正负，都是 Number 类型的。</p>
<h3 id="数值范围"><a href="#数值范围" class="headerlink" title="数值范围"></a>数值范围</h3><p>由于内存的限制，ECMAScript 并不能保存世界上所有的数值。</p>
<ul>
<li><p>最大值：<code>Number.MAX_VALUE</code>，这个值为： 1.7976931348623157e+308</p>
</li>
<li><p>最小值：<code>Number.MIN_VALUE</code>，这个值为： 5e-324</p>
</li>
</ul>
<p>如果使用 Number 表示的变量超过了最大值，则会返回Infinity。</p>
<ul>
<li><p>无穷大（正无穷）：Infinity</p>
</li>
<li><p>无穷小（负无穷）：-Infinity</p>
</li>
</ul>
<p>注意：<code>typeof Infinity</code>的返回结果是number。</p>
<h3 id="NaN"><a href="#NaN" class="headerlink" title="NaN"></a>NaN</h3><p><strong>NaN</strong>：是一个特殊的数字，表示Not a Number，非数值。比如：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="string">"abc"</span> / <span class="number">18</span>);  <span class="comment">//结果是NaN</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">"abc"</span> * <span class="string">"abcd"</span>); <span class="comment">//按理说，字符串相乘是没有结果的，但如果你非要让JS去算，它就一定会给你一个结果。结果是NaN</span></span><br></pre></td></tr></table></figure>

<p>注意：<code>typeof NaN</code>的返回结果是 number。</p>
<p>Undefined和任何数值计算的结果为 NaN。NaN 与任何值都不相等，包括 NaN 本身。</p>
<p>另外，关于 isNaN() 函数，可以看下一篇文章。</p>
<h3 id="浮点数的运算"><a href="#浮点数的运算" class="headerlink" title="浮点数的运算"></a>浮点数的运算</h3><p>在JS中，整数的运算<strong>基本</strong>可以保证精确；但是<strong>小数的运算，可能会得到一个不精确的结果</strong>。所以，千万不要使用JS进行对精确度要求比较高的运算。</p>
<p>如下：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">0.1</span> + <span class="number">0.2</span>;</span><br><span class="line"><span class="built_in">console</span>.log(a);  <span class="comment">//打印结果：0.30000000000000004</span></span><br></pre></td></tr></table></figure>

<p>上方代码中，打印结果并不是0.3，而是0.30000000000000004。</p>
<p>我们知道，所有的运算都要转换成二进制去计算，然而，二进制是无法精确表示1/10的。因此存在小数的计算不精确的问题。</p>
<h3 id="连字符和加号的区别"><a href="#连字符和加号的区别" class="headerlink" title="连字符和加号的区别"></a>连字符和加号的区别</h3><p>键盘上的<code>+</code>可能是连字符，也可能是数字的加号。如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">console.log(&quot;我&quot; + &quot;爱&quot; + &quot;你&quot;);	&#x2F;&#x2F;连字符，把三个独立的汉字，连接在一起了</span><br><span class="line">console.log(&quot;我+爱+你&quot;);			&#x2F;&#x2F;原样输出</span><br><span class="line">console.log(1+2+3);				&#x2F;&#x2F;输出6</span><br></pre></td></tr></table></figure>

<p>输出：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">我爱你</span><br><span class="line">我+爱+你</span><br><span class="line">6</span><br></pre></td></tr></table></figure>

<p><strong>总结</strong>：如果加号两边<strong>都是</strong>数值，此时是加。否则，就是连字符（用来连接字符串）。</p>
<p>举例1：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="string">"1"</span>;</span><br><span class="line"><span class="keyword">var</span> b = <span class="number">2</span>;</span><br><span class="line"><span class="built_in">console</span>.log(a + b);</span><br></pre></td></tr></table></figure>

<p>控制台输出：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">12</span><br></pre></td></tr></table></figure>

<p>举例2：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var a &#x3D; 1;</span><br><span class="line">var b &#x3D; 2;</span><br><span class="line">console.log(&quot;a&quot; + b);	&#x2F;&#x2F;&quot;a&quot;就不是变量了！所以就是&quot;a&quot;+2 输出a2</span><br></pre></td></tr></table></figure>

<p>控制台输出：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a2</span><br></pre></td></tr></table></figure>

<p>于是我们明白了，在变量中加入字符串进行拼接，可以被同化为字符串。【重要】</p>
<h3 id="隐式转换"><a href="#隐式转换" class="headerlink" title="隐式转换"></a>隐式转换</h3><p>我们知道，<code>&quot;2&quot;+1</code>得到的结果其实是字符串，但是<code>&quot;2&quot;-1</code>得到的结果却是数值1，这是因为计算机自动帮我们进行了“<strong>隐式转换</strong>”。</p>
<p>也就是说，<code>-</code>、<code>*</code>、<code>/</code>、<code>%</code>这几个符号会自动进行隐式转换。例如：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="string">"4"</span> + <span class="number">3</span> - <span class="number">6</span>;</span><br><span class="line"><span class="built_in">console</span>.log(a);</span><br></pre></td></tr></table></figure>

<p>输出结果：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">37</span></span><br></pre></td></tr></table></figure>

<p>虽然程序可以对<code>-</code>、<code>*</code>、<code>/</code>、`%``这几个符号自动进行“隐式转换”；但作为程序员，我们最好自己完成转换，方便程序的可读性。</p>
<h2 id="布尔值：Boolean"><a href="#布尔值：Boolean" class="headerlink" title="布尔值：Boolean"></a>布尔值：Boolean</h2><p>布尔型有两个值：true 和 false。主要用来做逻辑判断： true 表示真，false 表示假。</p>
<p>布尔值直接使用就可以了，千万不要加上引号。</p>
<p>代码：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="literal">true</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> a);</span><br></pre></td></tr></table></figure>

<p>控制台输出结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">boolean</span><br></pre></td></tr></table></figure>

<p>布尔型和数字型相加时， true 按 1 来算 ，false 按 0 来算。</p>
<h2 id="Null-和-Undefined"><a href="#Null-和-Undefined" class="headerlink" title="Null 和 Undefined"></a>Null 和 Undefined</h2><h3 id="null：空值"><a href="#null：空值" class="headerlink" title="null：空值"></a><code>null</code>：空值</h3><p>专门用来表示一个为空的<strong>对象</strong>（例如：<code>var a = null</code>）。注意，专门用来表示<strong>空对象</strong>。</p>
<ul>
<li><p>Null类型的值只有一个，就是null。比如 <code>var a = null</code>。</p>
</li>
<li><p>使用 typeof 检查一个null值时，会返回object。</p>
</li>
</ul>
<h3 id="undefined：未定义"><a href="#undefined：未定义" class="headerlink" title="undefined：未定义"></a><code>undefined</code>：未定义</h3><p><strong>声明</strong>了一个变量，但是没有<strong>赋值</strong>（例如：<code>var a;</code>），此时它的值就是 <code>undefined</code>。</p>
<ul>
<li><p>Undefined类型的值只有一个，就是undefind。比如</p>
</li>
<li><p>使用 type of 检查一个undefined时，会返回undefined。</p>
</li>
</ul>
<p>null和undefined有很大的相似性。看看null == undefined的结果(true)也就更加能说明这点。</p>
<p>但是null === undefined的结果(false)。它们虽然相似，但还是有区别的，其中一个区别是：和数字运算时，10 + null结果为：10；10 + undefined结果为：NaN。</p>
<ul>
<li><p>任何数据类型和undefined运算都是NaN;</p>
</li>
<li><p>任何值和null运算，null可看做0运算。</p>
</li>
</ul>
<h2 id="变量值的传递（赋值）"><a href="#变量值的传递（赋值）" class="headerlink" title="变量值的传递（赋值）"></a>变量值的传递（赋值）</h2><p>语句：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">a &#x3D; b;</span><br></pre></td></tr></table></figure>

<p>把b的值赋给a，b不变。</p>
<p>将等号右边的值，赋给左边的变量；等号右边的变量，值不变。</p>
<p>来做几个题目。</p>
<p>举例1：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">					 	&#x2F;&#x2F;a		b       c</span><br><span class="line">var a &#x3D; 1;              &#x2F;&#x2F;1</span><br><span class="line">var b &#x3D; 2;              &#x2F;&#x2F;1     2</span><br><span class="line">var c &#x3D; 3;              &#x2F;&#x2F;1     2       3</span><br><span class="line">a &#x3D; b + c;              &#x2F;&#x2F;5     2       3</span><br><span class="line">b &#x3D; c - a;              &#x2F;&#x2F;5     -2      3</span><br><span class="line">c &#x3D; a * b;              &#x2F;&#x2F;5     -2      -10</span><br><span class="line">console.log(a);</span><br><span class="line">console.log(b);</span><br><span class="line">console.log(c);</span><br></pre></td></tr></table></figure>

<p>输出：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">5</span><br><span class="line">-2</span><br><span class="line">-10</span><br></pre></td></tr></table></figure>

<p>举例2：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">						&#x2F;&#x2F;a    b     c</span><br><span class="line">var a &#x3D; 1;</span><br><span class="line">var b &#x3D; 2;</span><br><span class="line">var c &#x3D; 3;              &#x2F;&#x2F;1     2     3</span><br><span class="line">a &#x3D; a + b;              &#x2F;&#x2F;3     2     3</span><br><span class="line">b &#x3D; b + a;              &#x2F;&#x2F;3     5     3</span><br><span class="line">c &#x3D; c + b;              &#x2F;&#x2F;3     5     8</span><br><span class="line">console.log(a);  &#x2F;&#x2F;3</span><br><span class="line">console.log(b);  &#x2F;&#x2F;5</span><br><span class="line">console.log(c);  &#x2F;&#x2F;8</span><br></pre></td></tr></table></figure>

<p>输出：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">3</span><br><span class="line">5</span><br><span class="line">8</span><br></pre></td></tr></table></figure>

<p>举例3：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">				    &#x2F;&#x2F;a       b</span><br><span class="line">var a &#x3D; &quot;1&quot;;</span><br><span class="line">var b &#x3D; 2;          &#x2F;&#x2F;&quot;1&quot;     2</span><br><span class="line">a &#x3D; a + b;          &#x2F;&#x2F;&quot;12&quot;    2</span><br><span class="line">b &#x3D; b + a;          &#x2F;&#x2F;&quot;12&quot;    &quot;212&quot;</span><br><span class="line">console.log(a);     &#x2F;&#x2F;输出12</span><br><span class="line">console.log(b);     &#x2F;&#x2F;输出212</span><br></pre></td></tr></table></figure>

<p>输出：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">12</span><br><span class="line">212</span><br></pre></td></tr></table></figure>

<p>举例4：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">				  &#x2F;&#x2F;a         b</span><br><span class="line">var a &#x3D; &quot;1&quot;;</span><br><span class="line">var b &#x3D; 2;</span><br><span class="line">a &#x3D; b + a;       &#x2F;&#x2F;&quot;21&quot;       2</span><br><span class="line">b &#x3D; b + a;       &#x2F;&#x2F;&quot;21&quot;       &quot;221&quot;</span><br><span class="line">console.log(a);  &#x2F;&#x2F;21</span><br><span class="line">console.log(b)   &#x2F;&#x2F;221</span><br></pre></td></tr></table></figure>


<p>效果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">21</span><br><span class="line">221</span><br></pre></td></tr></table></figure>

<p>举例5：（这个例子比较特殊，字符串减去数字）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var a &#x3D; &quot;3&quot;;</span><br><span class="line">var b &#x3D; 2;</span><br><span class="line">console.log(a-b);</span><br></pre></td></tr></table></figure>


<p>效果：（注意，字符串 - 数值 = 数值）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">1</span><br></pre></td></tr></table></figure>


<blockquote>
<p><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3FpYW5ndXlpaGFvL1dlYg==" title="https://github.com/qianguyihao/Web">转载连接<i class="fa fa-external-link"></i></span></p>
</blockquote>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/javascript%E6%95%99%E7%A8%8B/" rel="tag"># javascript教程</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2017/05/12/02-JS%E5%8F%98%E9%87%8F/" rel="prev" title="javascript变量">
      <i class="fa fa-chevron-left"></i> javascript变量
    </a></div>
      <div class="post-nav-item">
    <a href="/2017/11/19/line-lineoverflow/" rel="next" title="html单行、多行文本溢出隐藏">
      html单行、多行文本溢出隐藏 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#变量的数据类型"><span class="nav-number">1.</span> <span class="nav-text">变量的数据类型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#为什么需要数据类型"><span class="nav-number">1.1.</span> <span class="nav-text">为什么需要数据类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JS中一共有六种数据类型"><span class="nav-number">1.2.</span> <span class="nav-text">JS中一共有六种数据类型</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#String-字符串"><span class="nav-number">2.</span> <span class="nav-text">String 字符串</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#语法"><span class="nav-number">2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#引号的注意事项"><span class="nav-number">2.2.</span> <span class="nav-text">引号的注意事项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#转义字符"><span class="nav-number">2.3.</span> <span class="nav-text">转义字符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取字符串的长度"><span class="nav-number">2.4.</span> <span class="nav-text">获取字符串的长度</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字符串拼接"><span class="nav-number">2.5.</span> <span class="nav-text">字符串拼接</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数值型：Number"><span class="nav-number">3.</span> <span class="nav-text">数值型：Number</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#数值范围"><span class="nav-number">3.1.</span> <span class="nav-text">数值范围</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#NaN"><span class="nav-number">3.2.</span> <span class="nav-text">NaN</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#浮点数的运算"><span class="nav-number">3.3.</span> <span class="nav-text">浮点数的运算</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#连字符和加号的区别"><span class="nav-number">3.4.</span> <span class="nav-text">连字符和加号的区别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#隐式转换"><span class="nav-number">3.5.</span> <span class="nav-text">隐式转换</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#布尔值：Boolean"><span class="nav-number">4.</span> <span class="nav-text">布尔值：Boolean</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Null-和-Undefined"><span class="nav-number">5.</span> <span class="nav-text">Null 和 Undefined</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#null：空值"><span class="nav-number">5.1.</span> <span class="nav-text">null：空值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#undefined：未定义"><span class="nav-number">5.2.</span> <span class="nav-text">undefined：未定义</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#变量值的传递（赋值）"><span class="nav-number">6.</span> <span class="nav-text">变量值的传递（赋值）</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="王志超"
      src="/images/logo.png">
  <p class="site-author-name" itemprop="name">王志超</p>
  <div class="site-description" itemprop="description">记录前端的点点滴滴</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">19</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3d6YzU3MDczODIwNQ==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wzc570738205"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vd2FuZ3poaWNoYW8v" title="博客园 → https:&#x2F;&#x2F;www.cnblogs.com&#x2F;wangzhichao&#x2F;"><i class="fa fa-fw fa-globe"></i>博客园</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cDovL21haWwucXEuY29tL2NnaS1iaW4vcW1fc2hhcmU/dD1xbV9tYWlsbWUmZW1haWw9eHJHOHBmLXo5dkgzLTRhM3RfaWxxYXM=" title="E-Mail → http:&#x2F;&#x2F;mail.qq.com&#x2F;cgi-bin&#x2F;qm_share?t&#x3D;qm_mailme&amp;email&#x3D;xrG8pf-z9vH3-4a3t_ilqas"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
      <span class="links-of-author-item">
        <a href="//shang.qq.com/wpa/qunwpa?idkey=f528775f242a7c39fe8512383febb8990e621bf97354c2fb82f6832097b7c501" target="_blank" rel="noopener" title="QQ群 → &#x2F;&#x2F;shang.qq.com&#x2F;wpa&#x2F;qunwpa?idkey&#x3D;f528775f242a7c39fe8512383febb8990e621bf97354c2fb82f6832097b7c501"><i class="fa fa-fw fa-qq"></i>QQ群</a>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cDovL3dhbmd6Yy53YW5nL3dlYnNvY2tldC8=" title="websocket → http:&#x2F;&#x2F;wangzc.wang&#x2F;websocket&#x2F;"><i class="fa fa-fw fa-comments"></i>websocket</span>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2015 – 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">王志超</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>




  




  
<script src="/js/local-search.js"></script>









<script>
if (document.querySelectorAll('div.pdf').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/pdfobject@2/pdfobject.min.js', () => {
    document.querySelectorAll('div.pdf').forEach(element => {
      PDFObject.embed(element.getAttribute('target'), element, {
        pdfOpenParams: {
          navpanes: 0,
          toolbar: 0,
          statusbar: 0,
          pagemode: 'thumbs',
          view: 'FitH'
        },
        PDFJS_URL: '/lib/pdf/web/viewer.html',
        height: element.getAttribute('height') || '700px'
      });
    });
  }, window.PDFObject);
}
</script>




  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: false,
      appId: '9fgm6JVbw8PrOlvp7LfsKjsh-gzGzoHsz',
      appKey: 'LReLvzSwPnBOAz5LiIgJsiDO',
      placeholder: "说点什么吧",
      avatar: 'mm',
      meta: guest,
      pageSize: '10' || 10,
      visitor: false,
      lang: 'zh-cn' || 'zh-cn',
      path: location.pathname,
      recordIP: false,
      serverURLs: ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
